package com.baizhi.cmfzdemo.service.impl;

import com.baizhi.cmfzdemo.dao.CmfzAlbumDao;
import com.baizhi.cmfzdemo.entity.CmfzAlbum;
import com.baizhi.cmfzdemo.service.CmfzAlbumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 54433 on 2019/4/4.
 */
@Service
public class CmfzAlbumServiceImpl implements CmfzAlbumService {
    //封装集合
    @Autowired
    private CmfzAlbumDao cmfzAlbumDao;
    @Override
    public Map queryAllCmfzAlbum(int page, int rows) {
        //获取总数数量
        Map map = new HashMap();
        int count = cmfzAlbumDao.getCount();
        int page2 = (page-1)*rows;
        try{
            List<CmfzAlbum> cmfzAlbums = cmfzAlbumDao.queryAllAlbum(page2, rows);
            map.put("total",count);
            map.put("rows",cmfzAlbums);
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println(map);
        System.out.println("111111111111111111");
        return map;
    }

    @Override
    public Map deleteCmfzAlbum(int[] ids) {
        Map map = new HashMap();
        try{
            cmfzAlbumDao.deleteAlbum(ids);
            System.out.println("执行了删除操作**************");
            map.put("delete",true);
        }catch (Exception e){
            e.printStackTrace();
            map.put("delete",false);
        }
        return map;
    }

    @Override
    public Map addCmfzAlbum(CmfzAlbum cmfzAlbum) {
        Map map = new HashMap();
        try {
            cmfzAlbumDao.addAlbum(cmfzAlbum);
            map.put("add", true);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            map.put("add", false);
        }
        return map;
    }

    @Override
    public Map updateCmfzAlbum(CmfzAlbum cmfzAlbum) {
        Map map = new HashMap();
        try {
            cmfzAlbumDao.updateAlbum(cmfzAlbum);
            map.put("updateOk", true);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            map.put("updateOk", false);
            e.printStackTrace();
        }
        return map;
    }

    @Override
    public List<CmfzAlbum> queryAllCmfzAlbumTree() {
        return cmfzAlbumDao.queryAllAlbumTree();
    }

    @Override
    public List<CmfzAlbum> showAllCmfzAlbum() {
        return cmfzAlbumDao.showAllCmfzAlbum();
    }
}
